package com.situ.mall.thread.consumer;

import java.util.LinkedList;

public class Panzi extends Object{
    private LinkedList<Cake> list = new LinkedList<>();

    public synchronized void putCake(Cake cake) {
        list.addLast(cake);
        //生产了蛋糕之后通知正在执行getCake等待的线程
        notifyAll();
        System.out.println("生产者线程 putCake notifyAll");
    }


    public synchronized Cake getCake() {
        if (list.size() <= 0) {//盘子里面没有蛋糕
            try {
                System.out.println("消费者线程 getCake wait");
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        Cake cake = list.removeFirst();
        return cake;
    }


}
